package com.kexio.file.config;

import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 文件存储配置属性
 * 
 * 统一管理文件存储相关的配置参数
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@ConfigurationProperties(prefix = "kexio.file.storage")
public class FileStorageProperties {
    
    /**
     * 默认存储提供者
     */
    private String defaultProvider = "local";
    
    /**
     * 默认存储桶名称
     */
    private String defaultBucket = "kexio-files";
    
    /**
     * 上传限制配置
     */
    private UploadLimits upload = new UploadLimits();
    
    /**
     * 本地存储配置
     */
    private LocalStorageConfig local = new LocalStorageConfig();
    
    /**
     * MinIO存储配置
     */
    private MinioStorageConfig minio = new MinioStorageConfig();
    
    /**
     * 阿里云OSS配置
     */
    private OssStorageConfig oss = new OssStorageConfig();
    
    /**
     * 腾讯云COS配置
     */
    private CosStorageConfig cos = new CosStorageConfig();
    
    /**
     * 七牛云Kodo配置
     */
    private QiniuStorageConfig qiniu = new QiniuStorageConfig();
    
    /**
     * 存储提供者配置映射
     */
    private Map<String, String> providers = new HashMap<>();
    
    /**
     * 分享链接配置
     */
    private ShareConfig share = new ShareConfig();
    
    // ==================== 内部配置类 ====================
    
    /**
     * 上传限制配置
     */
    public static class UploadLimits {
        
        /**
         * 单文件最大大小（字节）
         */
        private long maxFileSize = 100 * 1024 * 1024; // 100MB
        
        /**
         * 批量上传最大文件数量
         */
        private int maxFileCount = 10;
        
        /**
         * 允许的文件类型（MIME类型）
         */
        private String[] allowedMimeTypes = {
            "image/*", "video/*", "audio/*", 
            "application/pdf", "application/msword", 
            "application/vnd.openxmlformats-officedocument.*",
            "text/*"
        };
        
        /**
         * 禁止的文件扩展名
         */
        private String[] blockedExtensions = {
            "exe", "bat", "cmd", "com", "pif", "scr", "vbs", "js"
        };
        
        /**
         * 是否启用病毒扫描
         */
        private boolean virusScanEnabled = false;
        
        // Getter/Setter
        public long getMaxFileSize() { return maxFileSize; }
        public void setMaxFileSize(long maxFileSize) { this.maxFileSize = maxFileSize; }
        
        public int getMaxFileCount() { return maxFileCount; }
        public void setMaxFileCount(int maxFileCount) { this.maxFileCount = maxFileCount; }
        
        public String[] getAllowedMimeTypes() { return allowedMimeTypes; }
        public void setAllowedMimeTypes(String[] allowedMimeTypes) { this.allowedMimeTypes = allowedMimeTypes; }
        
        public String[] getBlockedExtensions() { return blockedExtensions; }
        public void setBlockedExtensions(String[] blockedExtensions) { this.blockedExtensions = blockedExtensions; }
        
        public boolean isVirusScanEnabled() { return virusScanEnabled; }
        public void setVirusScanEnabled(boolean virusScanEnabled) { this.virusScanEnabled = virusScanEnabled; }
    }
    
    /**
     * 本地存储配置
     */
    public static class LocalStorageConfig {
        
        /**
         * 存储根目录
         */
        private String rootPath = "./storage";
        
        /**
         * 是否创建日期子目录
         */
        private boolean createDateSubDir = true;
        
        /**
         * 文件权限（Unix）
         */
        private String filePermissions = "644";
        
        /**
         * 目录权限（Unix）
         */
        private String dirPermissions = "755";
        
        // Getter/Setter
        public String getRootPath() { return rootPath; }
        public void setRootPath(String rootPath) { this.rootPath = rootPath; }
        
        public boolean isCreateDateSubDir() { return createDateSubDir; }
        public void setCreateDateSubDir(boolean createDateSubDir) { this.createDateSubDir = createDateSubDir; }
        
        public String getFilePermissions() { return filePermissions; }
        public void setFilePermissions(String filePermissions) { this.filePermissions = filePermissions; }
        
        public String getDirPermissions() { return dirPermissions; }
        public void setDirPermissions(String dirPermissions) { this.dirPermissions = dirPermissions; }
    }
    
    /**
     * MinIO存储配置
     */
    public static class MinioStorageConfig {
        
        /**
         * 是否启用
         */
        private boolean enabled = false;
        
        /**
         * 服务端点
         */
        private String endpoint;
        
        /**
         * 访问密钥
         */
        private String accessKey;
        
        /**
         * 密钥
         */
        private String secretKey;
        
        /**
         * 是否使用HTTPS
         */
        private boolean secure = false;
        
        /**
         * 区域
         */
        private String region = "us-east-1";
        
        /**
         * 连接超时（秒）
         */
        private int connectTimeout = 30;
        
        /**
         * 读取超时（秒）
         */
        private int readTimeout = 60;
        
        // Getter/Setter
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public String getEndpoint() { return endpoint; }
        public void setEndpoint(String endpoint) { this.endpoint = endpoint; }
        
        public String getAccessKey() { return accessKey; }
        public void setAccessKey(String accessKey) { this.accessKey = accessKey; }
        
        public String getSecretKey() { return secretKey; }
        public void setSecretKey(String secretKey) { this.secretKey = secretKey; }
        
        public boolean isSecure() { return secure; }
        public void setSecure(boolean secure) { this.secure = secure; }
        
        public String getRegion() { return region; }
        public void setRegion(String region) { this.region = region; }
        
        public int getConnectTimeout() { return connectTimeout; }
        public void setConnectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; }
        
        public int getReadTimeout() { return readTimeout; }
        public void setReadTimeout(int readTimeout) { this.readTimeout = readTimeout; }
    }
    
    /**
     * 阿里云OSS配置
     */
    public static class OssStorageConfig {
        
        /**
         * 是否启用
         */
        private boolean enabled = false;
        
        /**
         * 服务端点
         */
        private String endpoint;
        
        /**
         * 访问密钥ID
         */
        private String accessKeyId;
        
        /**
         * 访问密钥密码
         */
        private String accessKeySecret;
        
        /**
         * STS令牌（可选）
         */
        private String securityToken;
        
        // Getter/Setter
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public String getEndpoint() { return endpoint; }
        public void setEndpoint(String endpoint) { this.endpoint = endpoint; }
        
        public String getAccessKeyId() { return accessKeyId; }
        public void setAccessKeyId(String accessKeyId) { this.accessKeyId = accessKeyId; }
        
        public String getAccessKeySecret() { return accessKeySecret; }
        public void setAccessKeySecret(String accessKeySecret) { this.accessKeySecret = accessKeySecret; }
        
        public String getSecurityToken() { return securityToken; }
        public void setSecurityToken(String securityToken) { this.securityToken = securityToken; }
    }
    
    /**
     * 腾讯云COS配置
     */
    public static class CosStorageConfig {
        
        /**
         * 是否启用
         */
        private boolean enabled = false;
        
        /**
         * 应用ID
         */
        private String appId;
        
        /**
         * 密钥ID
         */
        private String secretId;
        
        /**
         * 密钥
         */
        private String secretKey;
        
        /**
         * 区域
         */
        private String region;
        
        // Getter/Setter
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public String getAppId() { return appId; }
        public void setAppId(String appId) { this.appId = appId; }
        
        public String getSecretId() { return secretId; }
        public void setSecretId(String secretId) { this.secretId = secretId; }
        
        public String getSecretKey() { return secretKey; }
        public void setSecretKey(String secretKey) { this.secretKey = secretKey; }
        
        public String getRegion() { return region; }
        public void setRegion(String region) { this.region = region; }
    }
    
    /**
     * 七牛云Kodo配置
     */
    public static class QiniuStorageConfig {
        
        /**
         * 是否启用
         */
        private boolean enabled = false;
        
        /**
         * AccessKey
         */
        private String accessKey;
        
        /**
         * SecretKey
         */
        private String secretKey;
        
        /**
         * 存储区域
         */
        private String region = "z0"; // 华东-浙江
        
        /**
         * CDN域名（用于访问）
         */
        private String domain;
        
        /**
         * 是否使用HTTPS
         */
        private boolean useHttps = true;
        
        // Getter/Setter
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public String getAccessKey() { return accessKey; }
        public void setAccessKey(String accessKey) { this.accessKey = accessKey; }
        
        public String getSecretKey() { return secretKey; }
        public void setSecretKey(String secretKey) { this.secretKey = secretKey; }
        
        public String getRegion() { return region; }
        public void setRegion(String region) { this.region = region; }
        
        public String getDomain() { return domain; }
        public void setDomain(String domain) { this.domain = domain; }
        
        public boolean isUseHttps() { return useHttps; }
        public void setUseHttps(boolean useHttps) { this.useHttps = useHttps; }
    }
    
    /**
     * 分享链接配置
     */
    public static class ShareConfig {
        /**
         * 分享链接基础地址，例如: https://files.example.com
         */
        private String baseUrl;
        /**
         * 分享路径前缀，例如: /share/
         */
        private String pathPrefix = "/share/";
        
        public String getBaseUrl() { return baseUrl; }
        public void setBaseUrl(String baseUrl) { this.baseUrl = baseUrl; }
        public String getPathPrefix() { return pathPrefix; }
        public void setPathPrefix(String pathPrefix) { this.pathPrefix = pathPrefix; }
    }
    
    // ==================== 主配置Getter/Setter ====================
    
    public String getDefaultProvider() {
        return defaultProvider;
    }
    
    public void setDefaultProvider(String defaultProvider) {
        this.defaultProvider = defaultProvider;
    }
    
    public String getDefaultBucket() {
        return defaultBucket;
    }
    
    public void setDefaultBucket(String defaultBucket) {
        this.defaultBucket = defaultBucket;
    }
    
    public UploadLimits getUpload() {
        return upload;
    }
    
    public void setUpload(UploadLimits upload) {
        this.upload = upload;
    }
    
    public LocalStorageConfig getLocal() {
        return local;
    }
    
    public void setLocal(LocalStorageConfig local) {
        this.local = local;
    }
    
    public MinioStorageConfig getMinio() {
        return minio;
    }
    
    public void setMinio(MinioStorageConfig minio) {
        this.minio = minio;
    }
    
    public OssStorageConfig getOss() {
        return oss;
    }
    
    public void setOss(OssStorageConfig oss) {
        this.oss = oss;
    }
    
    public CosStorageConfig getCos() {
        return cos;
    }
    
    public void setCos(CosStorageConfig cos) {
        this.cos = cos;
    }
    
    public QiniuStorageConfig getQiniu() {
        return qiniu;
    }
    
    public void setQiniu(QiniuStorageConfig qiniu) {
        this.qiniu = qiniu;
    }
    
    public Map<String, String> getProviders() {
        return providers;
    }
    
    public void setProviders(Map<String, String> providers) {
        this.providers = providers;
    }
    
    public ShareConfig getShare() { return share; }
    public void setShare(ShareConfig share) { this.share = share; }
}
